/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 16:06:20
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-04-23 17:30:13
 */
import { uploadType,regularRule, getAreaObj,getBaseAreaData } from '@/utils/util'
import { getStore } from '@/utils/store'
import { cloneDeep } from 'lodash-es'

let currentYear =  String(new Date().getFullYear())
// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '归属年份', prop: 'belongYear' },
		{
			label: '改造实施单位',
			prop: 'reformUnit',
		},
		{
			label: '监督单位',
			prop: 'monitor',
		},
		{
			label: '过程监督材料',
			type:"upload",
			prop: 'material1',
		},
		{
			label: '提交人',
			prop: 'createUserName',
		},
		{
			label: '提交时间',
			prop: 'createTime',
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

const formConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	column:[
		{
			label:"适老化改造项目归属年份",
			prop:"belongYear",
			type:"year",
			format:'YYYY年',
			valueFormat:"YYYY",
			defaultValue:currentYear,
			span:24,
			rules:[
				{required:true,message:"请填写适老化改造项目归属年份"}
			]
		},
		{
			label:"改造实施单位",
			prop:"reformUnit",
			// propName:"reformUnit",
            // type: 'autoSelect',
			// api: 'view_bscAdaptOldImplementation_page',
			// filterKey: 'implementationUnitName',
			// filterLabel: 'implementationUnitName',
			// multiple: false,
			// change:(item, form, value)=>{

			// },
			rules:[
				{required:true,message:"请填写改造实施单位"}
			],
			span:24
		},
        {
			label:"监督单位",
			prop:"monitor",
			span:24,
			rules:[
				{required:true,message:"请填写监督单位"}
			]
		},
        {
            label:"过程监督材料",
            type:'upload',
			// apiName: 'ost_uploadFile2',
			prop:"material",
			fileType:'application/pdf,image/png,image/jpg,image/jpeg',
            accept:'.pdf,.png,.jpg,.jpeg',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			multiple: true,
			uploadTip:"上传文件（pdf、图片）",
			span:24,
			rules:[
				{required:true,message:"请上传过程监督材料"}
			]
        },
	
	]
}

export const api = {
	index: 'view_bscAdaptMonitor_page',
	add: 'view_bscAdaptMonitor_add',
	detail:"view_bscAdaptMonitor_view",
	edit: 'view_bscAdaptMonitor_edit',
	delete: 'view_bscAdaptMonitor_del',
	export:"view_bscAdaptMonitor_export",
	import:"view_bscAdaptOld_monitor_import"
}

export const baseConfig = {
	pageName: '适老化改造监督管理',
	// 数据字典
	dictcodes: [],
	rowKey: 'id',
	tipLabel: 'monitor',
	addLabel: '新增',
	importLabel:'批量导入',
	api: {
		...api,
	},
	auth: {
		...api,
		mulitSet:'mulitSet',
	},
	paramsObj:{
		
	},
	// 当前行操作按钮
	menuBtn: [
		{
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		},
	
		{
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth:api.edit,
			condition: "(row)=>(row.isEditDel)",
			text: true,
			show: true,
		},
		{
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: api.delete,
			condition: "(row)=>(row.isEditDel)",
			text: true,
			show: true,
		}
	],
	detailConfig:formConfig,
	importConfig :{
		tabSteps: [
			{
				label: '下载模板',
				download: '下载模板',
				active: 1,
				rules: [
					{
						label: '下载最新导入模板。共1个：',
						children: [
							{
								label: '《适老化改造过程监督信息表》',
								link: true,
								url: 'view_bscAdaptOld_monitor_downloadTemplate',
							},
						],
					},
				],
			},
			{
				label: '导入《适老化改造过程监督信息表》',
				description: '',
				uploadTip: '适老化改造过程监督信息表',
				active: 2,
				url: 'view_bscAdaptOld_monitor_import',
				code: 4010,
				rules: [
					{
						label: '导入规则说明:',
						children: [
							{
								label: '(1)导入模式为“覆盖导入”，待导入的适老化改造过程监督信息表会覆盖平台已存在的',
							},
						],
					},
				],
			},
		],
	},
	formConfig,
	dialogConfig: {
		width: '80%',
	},
	// 搜索
	searchConfig: {
		inline: true,
		showBtn: true,
		labelPosition: 'left',
		column: [
			// { label: '适老化改造项目名称', prop: '', type: 'input', span: 8 },
			{ label: '改造实施单位', prop: 'reformUnit', type: 'input', span: 8 },
			{
				label: '监督单位',
				prop: 'monitor',
				span: 8,
			},
			{
				label: '提交人',
				prop: 'createUserName',
				span: 8,
			},
			{
				label: '提交时间',
				type:"daterange",
				prop: 'createTimeBetween',
				format: 'YYYY年MM月DD',
				valueFormat: 'YYYY-MM-DD',
				span:12,
			}
		],
	},
	// 列表
	tableConfig,
    saveFormate: async (form) => {
        let copyForm = cloneDeep(form)
		return new Promise((resolve, reject) => {
			resolve(copyForm)
		})
	},
	onLoadFormate: async (arr) => {
		let tableData = arr.map((item) => {
			item.material1 = item.material
			// 处理编辑和删除控制
			let userInfo = getStore('userInfo')
			if(userInfo.classifyId==3){
				// 行政用户，用区域判断
				if(getBaseAreaData(item).myAreaId==getBaseAreaData(userInfo).myAreaId&&item.authOrganizationId==userInfo.organizationId){
					item.isEditDel = true
				}else{
					item.isEditDel = false
				}
			}else if(userInfo.classifyId==5){
				// 服务商
				if(item.authOrganizationId==userInfo.organizationId){
					item.isEditDel = true
				}else{
					item.isEditDel = false
				}
			}
			return item
		})
		return Promise.resolve(tableData)
	},
	beforeOnLoadFormate(form) {
		let copyForm = cloneDeep(form)
		// 处理搜索条件
		if(copyForm.createTimeBetween){
			copyForm.createTimeBetween[0]=copyForm.createTimeBetween[0]+' 00:00:00'
			copyForm.createTimeBetween[1]=copyForm.createTimeBetween[1]+' 23:59:59'
			copyForm.createTimeBetween = copyForm.createTimeBetween.join(',')
		}

		return new Promise((resolve, reject) => {
			resolve(copyForm)
		})
	},
}
